package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 这个配置类用来添加文件访问的访问路径映射规则
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**配置上传文件的静态资源访问路径*/
        String imgPath = System.getProperty("user.dir") + "/upload/";
        registry.addResourceHandler("/upload/**") //虚拟url路径
                .addResourceLocations("file:" + imgPath); //真实本地路径

//        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/",
//                "classpath:/resources/", "classpath:/static/", "classpath:/public/");
    }
}
